-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use node-level | for efficiency in infix_spaces_linter #2025
Conversation
I started a Wiki page here: https://github.com/r-lib/lintr/wiki/Writing-robust,-performant-linters My first thought was to add notes like this or an efficiency/"advanced" section to the custom_linters vignette, but I think a Wiki may be preferable here for reasons noted there. |
The |
how about //OP[parent::expr[count(expr) >2]] untested but hopefully it's clear what I mean -- test against unary operator on parent instead of self |
Worth a try. |
Not quite so simple (h/t our extensive test suite!), but the basic idea works. The complications for future reference were:
|
R/infix_spaces_linter.R
Outdated
({xp_or(paste0('self::', infix_tokens))}) | ||
and position() > 1 | ||
xpath <- paste(collapse = "|", glue::glue("//{infix_tokens}[ | ||
parent::*[count(expr) + count(SYMBOL_SUB) > 1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is count(expr | SYMBOL_SUB)
a thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I still don't have a good sense of when |
can be used like this. It passed tests locally, so let's go for it!
Codecov Report
@@ Coverage Diff @@
## main #2025 +/- ##
==========================================
- Coverage 98.55% 98.55% -0.01%
==========================================
Files 113 113
Lines 4995 4994 -1
==========================================
- Hits 4923 4922 -1
Misses 72 72
|
Do we have a test for something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work.
Similar to #2024, I found
infix_spaces_linter()
to be among the slowest, and apparently owing to the//*
expression.It's really slow! Even with 22 entries in
//NODE1[...] | //NODE2[...] | ... | //NODE22[...]
, I find this approach about 3x as fast in the core loop: